package com.jungle.bfi.entity;

import com.jungle.base.criteria.Condition;
import com.jungle.base.entity.BasePo;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.Specification;

import java.math.BigDecimal;

/**
 * [metadata]元数据描述信息，元数据清单中展示项
 */
@Setter
@Getter
@Entity
@Table(name = "t_api_metadata")
public class ApiMetadataPo extends BasePo<String> {
    @Id
    private String id;
    /**
     * 接口标识
     */
    private String apiId;
    /**
     * 父路径
     */
    private String parentPath;
    /**
     * 自己的路径
     */
    @Condition
    private String ownPath;
    private String name;
    private String title;
    /**
     * 原始类型
     */
    private String originType;
    /**
     * 数据类型
     */
    private String type;
    /**
     * 数据格式
     */
    private String format;
    /**
     * 描述信息
     */
    private String description;
    private BigDecimal maximum;
    private BigDecimal minimum;
    /**
     * 引用元数据标识
     */
    private String ref;

    public Specification<ApiMetadataPo> toChildSpec() {
        return (root, query, cb) -> cb.and(
                cb.equal(root.get("apiId"), apiId),
                cb.equal(root.get("parentPath"), ownPath)
        );
    }
}
